/**
 * Created by Administrator on 2015/4/24.
 */
var fs = require('fs');
var exec = require('child_process').exec;

var name = 'main.css';
var out = 'build.css';
var optimizeCss = 'standard';
var paths = {
    'animate.css': 'scripts/animate.css',
    'font-awesome': 'scripts/font-awesome/css/font-awesome',
    'bootstrap': 'scripts/bootstrap/dist/js/bootstrap',
    'summernote': 'scripts/summernote/dist/summernote',
    'fonts': 'http://fonts.useso.com/css?family=Ubuntu:400,500,700,400italic,500italic',
    'art-dialog': 'scripts/art-dialog/css/ui-dialog.css',
    'tagsinput': 'scripts/bootstrap-tagsinput/dist/bootstrap-tagsinput'
};
var cssList = ['bootstrap/../../css/bootstrap.css', 'animate.css/animate.css', 'font-awesome', 'art-dialog', 'summernote/../summernote.css', 'fonts', 'tagsinput'];
var _pathList = [];
cssList.forEach(function (n) {
    var loc = n;
    var path = '';
    loc.split('/').forEach(function (m, i) {
        if (i === 0) {
            m = paths[m] || m;
        }
        path += m + '/';
    }, '');
    path = path.slice(0, -1);
    if (path.indexOf('http:') === 0) {
        _pathList.unshift('@import url(\'' + path + '\');\n');
    } else {
        path = (path.lastIndexOf('.css') !== path.length - 4 ) ? path + '.css' : path;
        _pathList.push('@import url(\'' + path + '\');\n');
    }
});
//console.log(_pathList);

fs.appendFile(name, _pathList.join(''), function (err) {
    if (err) {
        throw err;
    }
    exec('node r.js -o cssIn=' + name + ' out=' + out + ' optimizeCss=' + (optimizeCss || 'standard'));
   // fs.unlink(name);
});



